<template>
	<view>
		<view class="newsList"
			v-for="(item,index) in newsList"
			:key="index"
			@tap="goNewsDet(item.id)"
		>
			<view class="newsCover">
				<image class="samePar" src="../../../static/images/index/newsDef.png" v-if="item.headImg == ''"></image>
				<image class="samePar" :src="getCloudFilePath(item.headImg)" v-else mode="aspectFill"></image>
			</view>
			<view class="newsContent">
				<view class="newsTit multiEllip clamp2">{{item.title}}</view>
				<view class="smInfo viewNum">浏览次数:{{item.viewNum}}次</view>
				<view class="smInfo pubTime">{{item.addTime}}</view>
			</view>
		</view>
		<loading-view :loading="loading"></loading-view>
	</view>
</template>

<script>
	import { getZzNewsList } from '@/api/news/index'
	export default {
		data(){
			return{
				newsList:[],
				nowPage:1,
				hasNextFlag:null,
				loading : false,
				isHasDataFlag:null
			}
		},
		onLoad(){
			this.loadNewsList();
		},
		onPullDownRefresh : function(){
			this.initParams();
			uni.stopPullDownRefresh();
		},
		onReachBottom : function(){
			if( !this.loading && this.hasNextFlag ){
				this.getZxsList(); 
			}
		},
		methods:{
			loadNewsList(){
				let { nowPage,newsList } = this;
				this.loading = true;
				var field = {page:this.nowPage,limit:this.limit };
				getZzNewsList(field).then(res=>{
					this.hasNextFlag = res.data.hasNext;
					nowPage += 1;
					newsList.push( ...res.data.datas );
					this.newsList = newsList;
					this.nowPage = nowPage;
					this.loading = false;
					this.isHasDataFlag = true;
				}).catch(err=>{
					this.loading = false;
					this.isHasDataFlag=false;
				});
			},
			initParams(){
				this.nowPage = 1;
				this.loading = false;
				this.newsList = [];
				this.loadNewsList();
			},
			goNewsDet(detId){
				uni.navigateTo({
					url:'/pages/subIndex/zzNews/newsDet?detId=' + detId
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		background: $pss-bg-primary;
	}
</style>
<style lang="scss" scoped>
	.newsList{
		display: flex;
		margin-bottom: 20rpx;
		padding: 15rpx 30rpx;
		background: #fff;
		.newsCover{
			width: 160rpx;
			height: 160rpx;
			flex-shrink: 0;
			margin-right: 15rpx;
			border-radius: 8rpx;
			.samePar{
				border-radius: inherit;
			}
		}
		.newsContent{
			flex: 1;
			.newsTit{
				font-size: 30rpx;
				color: $pss-text-color0;
				font-weight: 600;
				margin-bottom: 15rpx;
			}
			.smInfo{
				font-size: 26rpx;
				&.viewNum{
					color: $pss-text-color8;
					margin-bottom: 5rpx;
				}
				&.pubTime{
					color: $pss-text-colora;
				}
			}
		}
		&:last-child{
			margin-bottom: 0;
		}
	}
</style>